<?php

namespace app\common\model\product;

use app\shop\model\product\BrandModel;
use think\facade\Cache;
use app\common\model\BaseModel;

/**
 * 产品分类模型
 */
class Brand extends BaseModel
{
    protected $pk = 'id';
    protected $name = 'product_brand';


    public static function listData($where, $params, $with = [], $sort = '')
    {
        $where = self::disposeWhere($where);
        $model = new static();
        if (count($with) > 0) {
            $model = $model->with($with);
        }
        if (!empty($sort)) {
            $model = $model->order($sort);
        } else {
            $model = $model->order(self::baseOrder());
        }
        $model = self::assWhere($model, $where);
        $list = $model->paginate($params);
        return $list;
    }

    public static function createData($where)
    {
        $model = new static();
        $where['app_id'] = self::$app_id;
        $data = $model->save($where);
        return $data;
    }

    public static function one($where)
    {
        $model = new static();
        return $model->findOrFail($where);
    }

    public static function deleteData($where)
    {
        $model = new static();
        return $model->where(['id' => $where['id']])->delete();
    }

    public static function listAll($where = [], $with = [], $sort = '')
    {
        $model = new static();
        if (count($with) > 0) {
            $model = $model->with($with);
        }
        $model = self::assWhere($model, $where);
        if (!empty($sort)) {
            $model = $model->order($sort);
        } else {
            $model = $model->order(self::baseOrder());
        }
        $list = $model->select();
        return $list;
    }
}
